import { createStore, useStore as baseUseStore, Store } from 'vuex'
import { App, InjectionKey } from 'vue'
import { IStore } from './types'

import modules from './modules/index'

export const key: InjectionKey<Store<IStore>> = Symbol('store')

const store = createStore<IStore>({
  modules
})

// custom useStore composition API
export function useStore () {
  return baseUseStore(key)
}

export function setupStore (app: App) {
  app.use(store, key)
}

export default store
